//
//  DetailTableViewCell.m
//  Style
//
//  Created by 邓星洋 on 15/8/22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#define ViewWidth(v)                        v.frame.size.width
#define ViewHeight(v)                       v.frame.size.height
#import "YLDetailTableViewCell.h"
#import "YLDetail_model.h"
#import <SDWebImage/UIImageView+WebCache.h>


@implementation YLDetailTableViewCell
/* 初始化 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.headView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"head"]];
        [self.contentView addSubview:self.headView];
        
        self.backLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.backLabel];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        
        self.articleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.articleLabel];
        
        self.leftImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.leftImageView];
    }
    return self;
}

/* 布局 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.selectionStyle = 0;
    self.headView.frame = CGRectMake(ViewWidth(self) / 22, ViewHeight(self) / 20, ViewWidth(self) / 20 * 18, ViewHeight(self) / 10);
    self.backLabel.frame = CGRectMake(ViewWidth(self) / 22, ViewHeight(self) / 10, ViewWidth(self) / 20 * 18, ViewHeight(self.contentView) - (ViewHeight(self) / 20 + ViewHeight(self) / 10));
    self.backLabel.layer.cornerRadius = 5;
    self.backLabel.layer.masksToBounds = YES;
    self.backLabel.layer.borderWidth = 0.4;
    self.titleLabel.frame = CGRectMake(ViewWidth(self) / 22, ViewHeight(self) / 20, ViewWidth(self) / 20 * 18, ViewHeight(self) / 9);
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = 1;
    self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    
    self.articleLabel.frame = CGRectMake(ViewWidth(self) / 21 * 10, ViewHeight(self) / 20 * 5, ViewWidth(self) / 20 * 9, ViewHeight(self) / 10 * 6);
    self.articleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.articleLabel.numberOfLines = 0;
    self.articleLabel.textColor = [UIColor blackColor];
    
    self.leftImageView.frame = CGRectMake(ViewWidth(self) / 10, ViewHeight(self) / 20 * 5, ViewHeight(self) / 10 * 6, ViewHeight(self) / 10 * 6);
//    self.leftImageView.layer.cornerRadius = ViewHeight(self) / 10 * 6 / 2;
//    self.leftImageView.layer.masksToBounds = YES;
}

/* 赋值 */
- (void)setDetail_model:(YLDetail_model *)detail_model
{
    if (detail_model.title.length > 19) {
        NSString *str = [detail_model.title substringToIndex:18];
        self.titleLabel.text = [NSString stringWithFormat:@"▲%@···▲", str];
    } else
    {
        self.titleLabel.text = [NSString stringWithFormat:@"▲%@▲", detail_model.title];
    }
    if (detail_model.content.length > 30) {
        NSString *str = [detail_model.content substringToIndex:29];
        self.articleLabel.text = [NSString stringWithFormat:@"%@···", str];
    } else
    {
        self.articleLabel.text = detail_model.content;
    }
    
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:detail_model.coverimg] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
